package com.youlu.campus.admin.auth.shiro.filter;


import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by zhuhuaiqi on 2018/03/21.
 *
 * @author zhuhuaiqi
 * @since 2018/03/21
 */
public class LogoutAuthenticationFilter extends AuthenticationFilter {

    @Override
    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object
            mappedValue) throws Exception {
        boolean validRestult = super.isAccessAllowed(request, response, mappedValue);
        if (!validRestult) {
            return validRestult;
        }
        logger.debug("LogoutAuthenticationFilter isAccessAllowed");
        /*Subject subject = getSubject(request, response);
        subject.logout();*/
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        HttpServletResponse httpResponse = (HttpServletResponse) response;
        removeAccessToken(httpRequest, httpResponse);
        return true;
    }

    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws
            Exception {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        logger.debug("onAccessDenied loginUrl:{}", getLoginUrl());
        //ajax请求
        //WebUtils.issueRedirect(request, response, getLoginUrl());
        //ExceptionUtils.business(AuthErrorCode.USER_NOT_LOGIN);
        return true;
    }
}
